<template>
  <div class="about">
    <div>
      <input v-model="name"/> <br>
      <input v-model="password" /> <br>
      <button @click="login">登录</button>
    </div>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        name: '',
        password: ''
      }
    },
    methods: {
      login() {
        this.$axios.post('/api/login', {
          name: this.name,
          password: this.password
        }).then(res => {
          if (res.data.code === 1) { // 登录成功，跳转到 / 
            localStorage.setItem('isLogin', new Date().toLocaleDateString())
            this.$router.push('/')
          } else {
            alert(res.data.msg)
          }
        })
      }
    }
  }
</script>
